package close.mazegame.entity.projectile;

import close.mazegame.collision.Collidable;
import close.mazegame.entity.PhysicsEntity;
import close.mazegame.level.Level;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public abstract class Projectile extends PhysicsEntity implements Collidable {
	
	public Projectile(Vector2 pos, Level level, float angle){
		super(level);
		this.level = level;
		
		remove = false;
		
		BodyDef bodyDef = new BodyDef();
		bodyDef.type = BodyType.DynamicBody;
		bodyDef.position.set(pos);
		body = level.getWorld().createBody(bodyDef);
		
		CircleShape circle = new CircleShape();
		circle.setRadius(this.getXSize()/2);
		
		FixtureDef fixtureDef = new FixtureDef();
		fixtureDef.filter.categoryBits = EntityCategory.PROJECTILE.getBits();
		fixtureDef.shape = circle;
		fixtureDef.density = 4.0f; 
		fixtureDef.friction = 0.0f;
		fixtureDef.restitution = 1.0f;

		body.createFixture(fixtureDef);
		
		body.setUserData(this);
		
		circle.dispose();
		
		Vector2 v = new Vector2(0,0);
		v.x = (float) (Math.cos(Math.toRadians(angle)) * getSpeed());
		v.y = (float) (Math.sin(Math.toRadians(angle)) * getSpeed());
		body.setLinearVelocity(v);
	}
	
	public float getXSize(){
		return 0.125f;
	}
	
	public float getYSize(){
		return 0.125f;
	}
	
	protected abstract float getSpeed();
	
	public float getDamageMod(){
		return 1.0f;
	}
	
}
